package com.junko.core.base;


import com.github.pagehelper.PageInfo;
import com.junko.model.PageForm;
import com.junko.model.BaseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public abstract class BaseServiceImpl<T extends BaseModel> implements BaseService<T> {

    @Autowired
    private BaseDao<T> baseDao;

    public BaseDao<T> getBaseDao() {
        return baseDao;
    }

    public void setBaseDao(BaseDao<T> baseDao) {
        this.baseDao = baseDao;
    }

    @Override
    public boolean insert(T entity) {
        return baseDao.insert(entity)==1;
    }

    @Override
    public boolean insertSelective(T record) {
        return baseDao.insertSelective(record)==1;
    }

    @Override
    public T selectByPrimaryKey(Object id) {
        return baseDao.selectByPrimaryKey(id);
    }

    @Override
    public boolean updateByPrimaryKey(T record) {
        return baseDao.updateByPrimaryKey(record)==1;
    }

    @Override
    public boolean updateByPrimaryKeySelective(T record) {
        return baseDao.updateByPrimaryKeySelective(record)==1;
    }

    @Override
    public boolean deleteByPrimaryKey(Object id) {
        return baseDao.deleteByPrimaryKey(id)==1;
    }

    @Override
    public List<T> findTop(int top, String statementKey, Object parameter) {
        return baseDao.findTop(top, statementKey, parameter);
    }

    @Override
    public T findTopOne(String statementKey, Object parameter) {
        return baseDao.findTopOne(statementKey, parameter);
    }

    @Override
    public PageInfo<T> pageFind(String statementKey, PageForm pageForm, Object parameter) {
        return baseDao.pageFind(statementKey, pageForm, parameter);
    }

    @Override
    public <M> PageInfo<M> pageFindModel(String statementKey, PageForm pageForm, Object parameter) {
        return baseDao.pageFindModel(statementKey, pageForm, parameter);
    }
}